package com.his.service.impl;

import com.his.entity.BillsRecord;
import com.his.entity.ResponseResult;
import com.his.mapper.BillsRecordMapper;
import com.his.service.IBillsRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 * 医院账单流水表 服务实现类
 * </p>
 *
 * @author Demoon Liu
 * @since 2022-02-20
 */
@Service
public class BillsRecordServiceImpl extends ServiceImpl<BillsRecordMapper, BillsRecord> implements IBillsRecordService {

    @Resource
    public BillsRecordMapper billsRecordMapper;

    @Override
    public ResponseResult selectBillsByIdNo(BillsRecord billsRecord) {
        List<BillsRecord> billsRecords=billsRecordMapper.selectBillsByIdNo(billsRecord.getRegistrationid());
        if (Objects.isNull(billsRecords)) {
            return new ResponseResult(250, "查找信息失败", null);
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("billsRecord",billsRecords);
        return new ResponseResult(200, "查找信息成功", map);
    }

    @Override
    public ResponseResult selectAllBills() {
        List<BillsRecord>billsRecords=billsRecordMapper.selectAllBills();
        if (Objects.isNull(billsRecords)) {
            return new ResponseResult(250, "查找信息失败", null);
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("billsRecord",billsRecords);
        return new ResponseResult(200, "查找信息成功", map);
    }

    @Override
    public ResponseResult updateBillsStatus(BillsRecord billsRecord) {
        BillsRecord billsRecord1=billsRecordMapper.selectBillsById(billsRecord.getId());
        if (Objects.isNull(billsRecord1)) {
            return new ResponseResult(250, "查找信息失败", null);
        }
        billsRecord1.setRecordlist(billsRecord.getRecordlist());
        billsRecordMapper.updateBillsStatus(billsRecord1);
        return new ResponseResult(200, "更新信息成功", null);
    }

    @Override
    public ResponseResult insertBills(BillsRecord billsRecord) {
        LocalDateTime localDateTime=LocalDateTime.now();
        billsRecord.setCreatetime(localDateTime);
        billsRecordMapper.insertBills(billsRecord);
        return new ResponseResult(200, "添加信息成功", null);
    }
}
